package com.patzn.osgi.tracker.http.web;

import com.patzn.osgi.tracker.http.api.RequestHandler;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;

import java.util.Dictionary;
import java.util.Hashtable;

public class WebActivator implements BundleActivator {

    private ServiceRegistration<RequestHandler> serviceRegistration;

    @Override
    public void start(BundleContext bundleContext) throws Exception {
        Dictionary<String, Object> properties = new Hashtable<>();
        properties.put("http.url", "/home");
        serviceRegistration = bundleContext.registerService(RequestHandler.class, () -> "welcome to home", properties);
    }

    @Override
    public void stop(BundleContext bundleContext) throws Exception {
        serviceRegistration.unregister();
    }
}
